#version 460 core
out vec4 FragColor;

uniform vec3 objectColor;
uniform vec3 lightColor;
uniform vec3 lightPos;//给光源照着的物体说明一下光源的位置
uniform vec3 mViewPos;//观察者角度 也就是摄像机角度

in vec3 Normal;
in vec3 FragPos;

void main()
{
    //漫反射
    vec3 norm = normalize(Normal);
    vec3 lightDir = normalize(lightPos - FragPos);
    float diff = max(dot(norm, lightDir), 0.0);
    vec3 diffuse = diff * lightColor;
    //环境光
    float ambientStrength = 0.1;
    vec3 ambient = ambientStrength * lightColor;

    //高光部分
    float specularStrength = 0.5;
    vec3 viewDir = normalize(mViewPos - FragPos);//
    vec3 reflectDir = reflect(-lightDir, norm);//反射光向量

    //高光系数 32为材质的shininess
    float spec = pow(max(dot(viewDir,reflectDir), 0.0),32);
    vec3 specular = specularStrength * spec * lightColor;

    //vec3 result = ambient * objectColor * Normal;

    vec3 result = (ambient + diffuse + specular) * objectColor;
    FragColor = vec4(result, 1.0);
   // FragColor = vec4(lightColor * objectColor, 1.0);
    //FragColor = vec4(1.0,1.0,0.0,1.0);


}